using Front._1117_2;
using MySqlConnector;

namespace Front._1127;

public partial class login : Form
{
    public login()
    {
        InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
        using var connection = new MySqlConnection("server=localhost;port=3306;database=book;user=root;password=@Zyl0903065;charset=utf8mb4;AllowPublicKeyRetrieval=True;");
        connection.Open();
        string sql = "SELECT * FROM admin_info where admin_account=@account and admin_password=@pwd;";
        string account = this.textBox1.Text;
        string password = this.textBox2.Text;
        using var command = new MySqlCommand(sql, connection);
        string pwd=MD5Helper.GetMD5(password);
        command.Parameters.AddWithValue("account", account);
        command.Parameters.AddWithValue("pwd", pwd);
        using var reader = command.ExecuteReader();
        if (reader.HasRows)
        {
            MainForm mainForm = new MainForm();
            mainForm.Show();
            this.Hide();
        }
        else
        {
            MessageBox.Show("账号密码错误");
            this.textBox1.Text="";
            this.textBox2.Text="";
        }
        while (reader.Read())
            Console.WriteLine(reader.GetInt32(0));
    }
    private void textBox1_TextChanged(object sender, EventArgs e)
    {
       
    }
}